Passed
Push — master ( 4c2534...c3984e )
by Christiaan
54s queued 10s
created

globalStateLens.test.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
/* eslint-env jest */
2
import { view, set, over, lensProp } from 'ramda'
3
import { inGlobalStateLens } from './globalStateLens'
4
5
it('Gets the global state', () => {
6
  const tokenLens = lensProp('token')
7
  const globalState = {
8
    store: {
9
      state: { token: 'HET_TOKEN' }
10
    }
11
  }
12
13
  const tokenLensInGlobal = inGlobalStateLens(tokenLens)
14
15
  expect(view(tokenLensInGlobal, globalState)).toBe('HET_TOKEN')
16
})
17
18
it('Sets in the global state', () => {
19
  const tokenLens = lensProp('token')
20
  const globalState = {
21
    store: {
22
      state: { token: 'HET_TOKEN' }
23
    }
24
  }
25
26
  const tokenLensInGlobal = inGlobalStateLens(tokenLens)
27
28
  expect(set(tokenLensInGlobal, 'NEW_TOKEN', globalState)).toStrictEqual({
29
    store: {
30
      state: { token: 'NEW_TOKEN' }
31
    }
32
  })
33
})
34
35
it('Runs a function over the lens value in the global state', () => {
36
  const tokenLens = lensProp('token')
37
  const globalState = {
38
    store: {
39
      state: { token: 'HET_TOKEN' }
40
    }
41
  }
42
43
  const tokenLensInGlobal = inGlobalStateLens(tokenLens)
44
45
  expect(
46
    over(tokenLensInGlobal, token => token + token, globalState)
47
  ).toStrictEqual({
48
    store: {
49
      state: { token: 'HET_TOKENHET_TOKEN' }
50
    }
51
  })
52
})
53